/**********************************************************************
The following class is defined to find out whether there are less than 20% campaign members in New Status under a campaign.
Author                Version            Date            Update
Arun Ramachandran     V 1.0            May 25th, 2011    
Arun Ramachandran     V 2.0            July 05, 2011    Instead of 20%, now offset will refer count less than 200. 

**********************************************************************/
public class CXGCampaignMemberCampaignUpdate{

public static void CampaignMemberToCampaignUpdate(list<CXG_Campaign_Accounts__c> CampMemList){

Set<ID> CampaignIDSet = new Set<ID>();

Decimal CountCampaignMember;
Decimal CountnewCampaignMember;
Decimal PercentageCount;

List<Campaign> CampaignList = new List<Campaign>();
List<Campaign> CampaignUpdateList = new List<Campaign>();

    for(CXG_Campaign_Accounts__c campMem: CampMemList){
    
    CampaignIDSet.add(campMem.Campaign__c); //Adding the Campaign ID of the associated Campaign Member in a Set.
    }
        
        // Total number of campaign members in that Campaign.
        //CountCampaignMember = [Select count() from CXG_Campaign_Accounts__c where Campaign__c in: CampaignIDSet]; 
        
        //Total number of Campaign members with 'New' as their Status in that Campaign.
        CountnewCampaignMember = [Select count() from CXG_Campaign_Accounts__c where Campaign__c in: CampaignIDSet AND Status__c ='New' AND Control_Group_Member__c = False ];
        
        //Calculating the percentage of New Campaign Members.
        //PercentageCount = ((CountnewCampaignMember/CountCampaignMember)*100);
        CampaignList = [Select offset__c from Campaign where Id in : CampaignIDSet ]; 
        
        
        
        for (Campaign camp: CampaignList){
            camp.Offset__c=CountnewCampaignMember; 
            CampaignUpdateList.add(camp); 
        }
    try{
    update CampaignUpdateList;
    }
    Catch(dmlexception e){
    System.debug(e);
    }     

}
}